package com.boofie.blog.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author boofie
 * @date 2021/8/20 21:32
 */
@Component
@Slf4j
public class CommonMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("Insert method executed!");
        this.setFieldValByName("created",new Date(),metaObject);
        this.setFieldValByName("modified",new Date(),metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("Update method executed!");
        this.setFieldValByName("modified",new Date(),metaObject);
    }
}
